package com.sgcc.fj.pmos.e_fj_home.presenter;

import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.e_fj_home.bean.UserTypeChangeBean;
import com.sgcc.fj.pmos.e_fj_home.bean.UserTypeListBean;
import com.sgcc.fj.pmos.e_fj_home.contract.UserTypeInfoContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class UserTypeInfoPresenter extends BasePresenter<UserTypeInfoContract.View> implements UserTypeInfoContract.Presenter {
    /**
     * 获取当前身份
     *
     */
    @Override
    public void getNowUserType(String tagetYear, int tagetMounth) {
        Map<String, Object> params = new HashMap<>();
        params.put("mktYear", tagetYear);
//        data.put("mktYear", 2022);

        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_QUERYUSERTYPELIST, new MvpNetCallback<UserTypeListBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(UserTypeListBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if (response.getStatus() == 0) {
                        if (tagetMounth <= response.getData().size()) {
                            getView().queryNowUserSuccess(response.getData().get(tagetMounth-1));
                        } else {
                            ToastUtils.showShort("暂无目标月份身份信息");
                        }
                    } else {
                        ToastUtils.showShort(response.getMessage());
                    }
                } else {
                    ToastUtils.showShort("身份列表请求失败");
                }

            }
        });



//        Map<String, Object> params = new HashMap<>();
//        params.put("tagetMonth", tagetMonth);
//        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_USERTYPE_CHANGE, new MvpNetCallback<UserTypeChangeBean>(getView(), true) {
//            @Override
//            public void onError(Call call, Exception e, int id) {
//                super.onError(call, e, id);
//                // 失败回调 判断界面是否销毁
//                if (!isViewAttached()) {
//                    return;
//                }
//                getView().queryNowUserFaile();
//            }
//
//            @Override
//            public void onResponse(UserTypeChangeBean response, int id) {
//                super.onResponse(response, id);
//                if (!isViewAttached()) {
//                    return;
//                }
//                getView().queryNowUserSuccess(response);
//            }
//        });
    }


    /**
     * 获取下季度第一个月身份类型
     */
    @Override
    public void getNextUserType(String tagetMonth) {
        Map<String, Object> params = new HashMap<>();
        params.put("tagetMonth", tagetMonth);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_USERTYPE_CHANGE, new MvpNetCallback<UserTypeChangeBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().queryNextUserTypeFaile();
            }

            @Override
            public void onResponse(UserTypeChangeBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().queryNextUserTypeSuccess(response);
            }
        });
    }

    /**
     * 获取下季度第一个月身份类型
     */
    @Override
    public void getTagetUserType(String tagetYear, int tagetMounth) {

        Map<String, Object> params = new HashMap<>();
        params.put("mktYear", tagetYear);
//        data.put("mktYear", 2022);

        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_QUERYUSERTYPELIST, new MvpNetCallback<UserTypeListBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(UserTypeListBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if (response.getStatus() == 0) {
                        if (tagetMounth <= response.getData().size()) {
                            getView().getTypeListSuccess(response.getData().get(tagetMounth-1));
                        } else {
                            ToastUtils.showShort("暂无目标月份身份信息");
                        }
                    } else {
                        ToastUtils.showShort(response.getMessage());
                    }
                } else {
                    ToastUtils.showShort("身份列表请求失败");
                }

            }
        });

        //        Map<String, Object> params = new HashMap<>();
//        params.put("tagetMonth", tagetMonth);
//        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_USERTYPE_CHANGE, new MvpNetCallback<UserTypeChangeBean>(getView(), true) {
//            @Override
//            public void onError(Call call, Exception e, int id) {
//                super.onError(call, e, id);
//                // 失败回调 判断界面是否销毁
//                if (!isViewAttached()) {
//                    return;
//                }
////                getView().queryNextUserTypeFaile();
//            }
//
//            @Override
//            public void onResponse(UserTypeChangeBean response, int id) {
//                super.onResponse(response, id);
//                if (!isViewAttached()) {
//                    return;
//                }
//                getView().getTagetUserTypeSuccess(response);
//            }
//        });
    }

}
